﻿using System.Data;
using LibDBConnect;

namespace LibDataLayer
{
    public static class DALMessage
    {
        private static readonly SqlHelper Cls = new SqlHelper();
        #region[Get-Data]
        public static DataTable GetMessage(string UserId_To)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("UserId_To", UserId_To);
            return Cls.GetData("sp_Message_s_Get");
        }
        public static DataTable GetMessageCount(string UserId_To)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("UserId_To", UserId_To);
            return Cls.GetData("sp_Message_s_Get_Count");
        }
        public static DataTable GetMessageEdit(int ID)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("ID", ID);
            return Cls.GetData("sp_Message_s_Get_Edit");
        }
        #endregion

        #region[Insert-Update-Delete]
        public static bool Insert(DTOMessage obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("UserId_From", obj.UserId_From);
            Cls.AddParameter("UserId_To", obj.UserId_To);
            Cls.AddParameter("Content", obj.Content);
            return Cls.ExecuteNonQuery("sp_Message_s_Insert");
        }
        public static bool Delete(DTOMessage obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("ID", obj.ID);
            return Cls.ExecuteNonQuery("sp_Message_s_Get_Delete");
        }
        #endregion
    }
    public class DTOMessage
    {
        public int ID { get; set; }
        public string UserId_From { get; set; }
        public string UserId_To { get; set; }
        public string Content { get; set; }
        public bool IsNew { get; set; }
    }
}